package org.dlsu.mt.parser.generation;
public class HTPLInterpreter
{
	public HTPLInterpreter()
	{
	}
	
	public String interpretPotentialWord(PotentialWord w)
	{
		return w.getWord();
	}
	
	public String interpretPhraseContent(PhraseContent c)
	{
		if(c != null)
			return interpretPhraseList(c.getList());
		return "";
	}
	
	public String interpretPhraseList(PhraseList l)
	{
		StringBuffer temp = new StringBuffer();
		for(int i=0; i<l.getNumElements();i++)
		{
			if(i!=0)
				temp.append(" ");
			ListElement e = l.getElement(i);
			if(e instanceof PotentialWord)
				temp.append(interpretPotentialWord((PotentialWord)e));
			else
				temp.append(interpretPhraseContent((PhraseContent)e));
		}
		while(temp.length()!=0&&temp.charAt(temp.length()-1) == ' ')
			temp = temp.deleteCharAt(temp.length()-1);
		return temp.toString();
	}
	
	public String interpret(Phrase p)
	{
		StringBuffer temp = new StringBuffer();
		for(int i=0; i<p.getNumElements();i++)
		{
			ListElement c = p.getElement(i);
			if(c instanceof PhraseContent)
			{
				PhraseContent pc = (PhraseContent)c;
				String tempStr = interpretPhraseContent(pc);
				temp.append(tempStr);
				if(!tempStr.equals(""))
					temp.append(" ");
			}
			else if(c instanceof PotentialWord)
			{
				PotentialWord pw = (PotentialWord)c;
				temp.append(interpretPotentialWord(pw));
				temp.append(" ");
			}
		}
		while(temp.length()!=0&&temp.charAt(temp.length()-1) == ' ')
			temp = temp.deleteCharAt(temp.length()-1);
		//temp.append(".");
		temp.setCharAt(0,Character.toUpperCase(temp.charAt(0)));
		return temp.toString();
	}
}